package com.qfedu.zf.user.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qfedu.zf.common.vo.R;
import com.qfedu.zf.user.entity.Coupon;
import com.qfedu.zf.user.entity.CouponAdd;
import com.qfedu.zf.user.mapper.CouponAddMapper;
import com.qfedu.zf.user.mapper.CouponMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zym
 * @since 2024-06-19
 */
@RestController
@RequestMapping("/user/coupon")
public class CouponController {
    @Autowired
    private CouponMapper couponMapper;
    @Autowired
    private CouponAddMapper couponAddMapper;

    @RequestMapping("/list")
    public R selectList(){
        return R.ok(couponMapper.selectList(null));
    }

    @RequestMapping(value = "/selectById")
    public R selectByCouponId(@RequestParam("id") Integer id){
        return R.ok(couponMapper.selectById(id));
    }

    @RequestMapping(value = "/add")
    public R couponAdd(@RequestParam("id") Integer id){
        Coupon coupon = new Coupon();
        CouponAdd couponAdd = couponAddMapper.selectById(id);
        coupon.setName(couponAdd.getName());
        coupon.setState(couponAdd.getState());
        coupon.setInfo(couponAdd.getInfo());
        coupon.setDiscount(couponAdd.getDiscount());
        coupon.setQuanma(couponAdd.getQuanma());
        coupon.setStartDate(couponAdd.getStartDate());
        coupon.setEndTime(couponAdd.getEndTime());

        couponAddMapper.deleteById(id);
        return R.ok(couponMapper.insert(coupon));
    }


}

